using System;
using System.Collections;
using System.Runtime.Serialization;

namespace Widgetsphere.Core.DataAccess
{
	[Serializable]
	public abstract partial class SelectCommand : ISerializable
	{
		private readonly Hashtable mParameterValues = new Hashtable();
		private int _timeOut = 0;

		public Hashtable ParameterValues
		{
			get { return mParameterValues; }
		}

		protected SelectCommand()
		{
		}

		protected SelectCommand(SerializationInfo info, StreamingContext context)
		{
			mParameterValues = (Hashtable)info.GetValue("mParameterValues", typeof(Hashtable));
		}

		public int TimeOut
		{
			get { return _timeOut; }
			set
			{
				if (value < 0)
					value = 0;
				_timeOut = value;
			}
		}

		#region abstract methods
		public abstract string StoredProcedureName { get;}
		protected abstract void SetupParameterValues(SubDomainBase subDomain);
		public abstract IDomainCollection CreateDomainCollection();
		public abstract string ConnectionString { get;}
		public abstract int DefaultTimeOut { get;}
		#endregion

		#region serialization
		public virtual void GetObjectData(SerializationInfo info, StreamingContext context)
		{
			info.AddValue("mParameterValues", mParameterValues);
		}
		#endregion

		public virtual IDomainCollection Execute(SubDomainBase subDomain)
		{
			this.SetupParameterValues(subDomain);
			var returnDomainCollection = this.CreateDomainCollection();
			returnDomainCollection.RunSelectCommand(this);
			return returnDomainCollection;
		}


	}

}
